package com.han.school.controller;

import com.github.pagehelper.PageInfo;
import com.han.school.pojo.Teacher;
import com.han.school.service.TeacherService;
import com.han.school.service.impl.TeacherServiceImpl;
import com.han.school.vo.TeacherVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.HandlerInterceptor;
import utils.HzdlJsonResult;

import java.util.List;

@Controller
public class TeacherController {
    @Autowired
    TeacherServiceImpl teacherService;
    @RequestMapping("/teacherall")
    @ResponseBody
    public HzdlJsonResult teaall(TeacherVo teacherVo){
        PageInfo<TeacherVo> teacherall = teacherService.teacherall(teacherVo);
        return HzdlJsonResult.ok(teacherall.getList(),Long.valueOf(teacherall.getTotal()).intValue());
    }
    @RequestMapping("/teacheradd")
    @ResponseBody
    public String teaadd(TeacherVo teacherVo){
        Integer add = teacherService.add(teacherVo);
        if (add > 0) {
            return "1";
        }else {
        return "0";
        }
    }
    @RequestMapping("/teacherdelete")
    @ResponseBody
    public String teadetele(TeacherVo teacherVo){
        Integer add = teacherService.delete(teacherVo);
        if (add > 0) {
            return "1";
        }else {
            return "0";
        }
    }
    @RequestMapping("/teacherup")
    @ResponseBody
    public String teaup(TeacherVo teacherVo){
        System.out.println(1);
        Integer add = teacherService.update(teacherVo);
        System.out.println(add);
        if (add > 0) {
            return "1";
        }else {
            return "0";
        }
    }
}
